package de.hpi.generator.generator.distributors;

import de.hpi.generator.config.DistributionModel;
import de.hpi.generator.config.DistributionModelSEQUENCE;
import de.hpi.generator.generator.storages.ValueSeriaInfo;
import java.util.Random;


/**
 * sequence distributor
 * @author Michael Wolowyk
 */
public class SequenceDistributor extends DataDistributor {

    Random aRandom = new Random();
    protected int aStartValue = aRandom.nextInt(Integer.MAX_VALUE);
    protected int aLastUsedValue = aStartValue;
    protected int aStep = 1;
    

    public String getName() {
        return "SEQUENCE";
    }

    
    /**
     * initialize default sequence distributor with random start and step = 1
     */
    public SequenceDistributor() {
        super();
        initClass(aStep, aStartValue);
    }

    
    
    public SequenceDistributor(int aStep, int aStartValue) {
        super();
        initClass(aStep,aStartValue);
    }

    protected void initClass(int aStep, int aStartValue) {
        this.aStep = aStep;
        this.aStartValue = aStartValue;
        this.aLastUsedValue = aStartValue;
        
    }
    
    public void setupRange(int aValuesCount) throws Exception {
        aNumberOfValuesToGenerate = aValuesCount;
        this.aAllValuesCount = aNumberOfValuesToGenerate;
    }

    @Override
    public int getCountOfValue(int aValue) throws Exception {
        return 1;
    }
    
        /**
     * setup object with specialized params
     * 
     * @param aSpecializedDistributionModel
     *            specialized params
     */
    @Override
    protected void setupObjectWithSpecializedParams(DistributionModel aSpecializedDistributionModel) throws Exception {
        super.setupObjectWithSpecializedParams(aSpecializedDistributionModel);
        // convert common type of aSpecializedDistributionModel object to
        // specialized type
        DistributionModelSEQUENCE aDistributionModelSEQUENCE = (DistributionModelSEQUENCE) aSpecializedDistributionModel;
        // setup distributor parameters
        this.initClass(aDistributionModelSEQUENCE.step, aDistributionModelSEQUENCE.start);
    }

        /**
     * generates random positive integer as value and cardinality for it
     * 
     * @return Value seria info with random positive integer as value and cardinality for it
     */
    @Override
    public ValueSeriaInfo generateNextRandomValueSeriaInfo() throws Exception {
        
        int aRandomInteger = aLastUsedValue;
        int aRandomIntegerCount = this.getCountOfValue(aRandomInteger);
        aLastUsedValue += aStep;
        return new ValueSeriaInfo(aRandomInteger, aRandomIntegerCount);
    }
}
